﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Diagnostics;
using System.Web.Configuration;

namespace Lilium.Web.Mvc.Configuration
{
	public abstract class ScriptResourceElement: ConfigurationElement
	{
		#region public string ContentType

		private const string ContentTypePropertyName = "contentType";

		[ConfigurationPropertyAttribute(ContentTypePropertyName)]
		public string ContentType { [DebuggerNonUserCodeAttribute] get { return (string)base[ContentTypePropertyName]; } [DebuggerNonUserCodeAttribute] set { base[ContentTypePropertyName] = value; } }

		#endregion

		#region public OutputCacheConfigurationElement OutputCache

		private const string OutputCachePropertyName = "outputCache";

		[ConfigurationPropertyAttribute(OutputCachePropertyName)]
		public OutputCacheConfigurationElement OutputCache { [DebuggerNonUserCodeAttribute] get { return (OutputCacheConfigurationElement)base[OutputCachePropertyName]; } [DebuggerNonUserCodeAttribute] set { base[OutputCachePropertyName] = value; } }

		#endregion

		#region public string Name

		private const string NamePropertyName = "name";

		[ConfigurationPropertyAttribute(NamePropertyName, IsRequired = true, IsKey = true)]
		public string Name { [DebuggerNonUserCodeAttribute] get { return (string)base[NamePropertyName]; } [DebuggerNonUserCodeAttribute] set { base[NamePropertyName] = value; } }

		#endregion

		public abstract ScriptResource GetScriptResource();

		protected OutputCachePolicy GetOutputCachePolicy()
		{
			return OutputCache.Inherited != false || ScriptResourceLibrary == null
				? OutputCache.GetCachePolicy()
				: ScriptResourceLibrary.GetCachePolicy();
		}

		protected string GetContentType()
		{
			return ContentType != null || ScriptResourceLibrary == null ? ContentType : ScriptResourceLibrary.ContentType;
		}

		#region protected internal ScriptResourceLibraryElement ScriptResourceLibrary

		private ScriptResourceLibraryElement m_ScriptResourceLibrary;

		protected internal ScriptResourceLibraryElement ScriptResourceLibrary { [DebuggerNonUserCodeAttribute] get { return m_ScriptResourceLibrary; } [DebuggerNonUserCodeAttribute] set { m_ScriptResourceLibrary = value; } }

		#endregion
	}
}